home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / emboxclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.2 KB  |  191 lines

  1. /* emboxclass.c -- :ts=8
  2.  * Example of a private image class.
  3.  * This one does a raised embossed box.
  4.  * Doesn't do resolution sensitive bevel widths yet,
  5.  * nor respect IA_LINEWIDTH.
  6.  */
  7.  
  8. /*
  9. Copyright (c) 1989, 1990 Commodore-Amiga, Inc.
  10.  
  11. Executables based on this information may be used in software
  12. for Commodore Amiga computers. All other rights reserved.
  13. This information is provided "as is"; no warranties are made.
  14. All use is at your own risk, and no liability or responsibility
  15. is assumed.
  16. */
  17.  
  18. #include "sysall.h"
  19.  
  20. #if 0    /* in sysall.h    */
  21. #include <intuition/classusr.h>
  22. #include <intuition/classes.h>
  23. #include <intuition/imageclass.h>
  24. #endif
  25.  
  26. #include <intuition/classes.h>
  27.  
  28. #include <graphics/gfxmacros.h>
  29.  
  30. #define D(x)    ;
  31. #define DH(x)    ;
  32.  
  33. #define IM(o)    ((struct Image *)(o))    /* transparent base class */
  34.  
  35. #define LINEWIDTH    (1)        /* not variable, not fancy    */
  36.  
  37. /* private class    */
  38. #define PRIVATECLASS    TRUE
  39.  
  40. #if PRIVATECLASS
  41. #define MYCLASSID    (NULL)
  42. extern struct Library    *IntuitionBase;
  43. #endif
  44.  
  45. #define SUPERCLASSID    (IMAGECLASS)
  46.  
  47. Class    *
  48. initEmbBClass()
  49. {
  50.     ULONG __saveds    dispatchEmbB();
  51.     ULONG    hookEntry();
  52.     Class    *cl;
  53.     Class    *MakeClass();
  54.  
  55.     if ( cl =  MakeClass( MYCLASSID, 
  56.         SUPERCLASSID, NULL,        /* superclass is public      */
  57.          0,                /* no new instance data */
  58.         0 ))
  59.     {
  60.     /* initialize the cl_Dispatcher Hook    */
  61.     cl->cl_Dispatcher.h_Entry = hookEntry;
  62.     cl->cl_Dispatcher.h_SubEntry = dispatchEmbB;
  63.     cl->cl_Dispatcher.h_Data = (VOID *) 0xFACE;    /* unused */
  64.  
  65. #if !PRIVATECLASS
  66.     AddClass( cl );            /* make public and available    */
  67. #endif
  68.     }
  69.     return ( cl );
  70. }
  71.  
  72. freeEmbBClass( cl )
  73. Class    *cl;
  74. {
  75.     return ( FreeClass( cl )  );
  76. }
  77.  
  78. ULONG __saveds 
  79. dispatchEmbB( cl, o, msg )
  80. Class   *cl;
  81. Object  *o;
  82. Msg     msg;
  83. {
  84.     switch ( msg->MethodID )
  85.     {
  86.     case IM_DRAW:            /* draw with state */
  87.     return ( (ULONG) drawEmbB( cl, o, msg ) );
  88.  
  89.     /* use superclass defaults for everything else */
  90.     case OM_NEW:
  91.     case OM_GET:
  92.     case OM_SET:
  93.     case IM_HITTEST:
  94.     case IM_ERASE:
  95.     case OM_DISPOSE:
  96.     default:
  97.     return ( (ULONG) DSM( cl, o, msg ) );
  98.     }
  99. }
  100.  
  101. drawEmbB( cl, o, msg )
  102. Class        *cl;
  103. Object        *o;
  104. struct impDraw    *msg;
  105. {
  106.     struct IBox        box;
  107.  
  108.     UWORD        *pens;        /* pen spec array */
  109.     UWORD        ulpen;        /* upper left    */
  110.     UWORD        lrpen;        /* lower right    */
  111.     UWORD        fillpen;    /* filled area    */
  112.  
  113.     /* let's be sure that we were passed a DrawInfo    */
  114.     pens =  ( msg->imp_DrInfo )?  msg->imp_DrInfo->dri_Pens: NULL;
  115.  
  116.     box = *IM_BOX( IM(o) );        /* get Image.Left/Top/Width/Height */
  117.     box.Left += msg->imp_Offset.X;
  118.     box.Top += msg->imp_Offset.Y;
  119.  
  120.     switch ( msg->imp_State )
  121.     {
  122.     case IDS_SELECTED:
  123.     case IDS_INACTIVESELECTED:
  124.     ulpen = pens? pens[ shadowPen ]: 2;
  125.     lrpen = pens? pens[ shinePen ]: 1;
  126.     fillpen = pens? pens[ hifillPen ]: 3;
  127.     break;
  128.  
  129.     case IDS_NORMAL:    /* doesn't use activefill in borders now */
  130.     case IDS_DISABLED:    /* I don't have a ghosted version yet     */
  131.     case IDS_INACTIVENORMAL:    /* doesn't use activefill in borders now */
  132.     default:
  133.     ulpen = pens? pens[ shinePen ]: 2;
  134.     lrpen = pens? pens[ shadowPen ]: 1;
  135.     fillpen = pens? pens[ backgroundPen ]: 0;
  136.     break;
  137.     }
  138.  
  139.     embossedBoxTrim( msg->imp_RPort, &box, LINEWIDTH, LINEWIDTH, ulpen,lrpen);
  140.  
  141.     /* interior */
  142.     interiorBox( msg->imp_RPort, &box, LINEWIDTH, LINEWIDTH, fillpen );
  143. }
  144.  
  145. /* fill region centered in a box */
  146. interiorBox( rp, b, xw, yw, pen )
  147. struct RastPort    *rp;
  148. struct IBox    *b;
  149. {
  150.     if ( (b->Width > (xw<<1)) && (b->Height > (yw<<1)) )
  151.     {
  152.     rp->Mask = -1;
  153.     BNDRYOFF( rp );
  154.     SetAfPt(rp, NULL, 0);
  155.     SetDrMd(rp, JAM2);
  156.     SetAPen(rp, pen);
  157.     RectFill( rp,
  158.         b->Left + xw,
  159.         b->Top + yw,
  160.         b->Left + b->Width - 1 - xw,
  161.         b->Top + b->Height - 1 - yw );
  162.     }
  163. }
  164.  
  165. /* suggestion of Talin: don't draw upper-right and lower-left points */
  166. /* ignoring thickness for now    */
  167. embossedBoxTrim( rp, b, hthick, vthick, ulpen, lrpen )
  168. struct RastPort    *rp;
  169. struct IBox    *b;
  170. {
  171.     int    bottom, right;
  172.  
  173.     bottom = b->Top + b->Height - 1;
  174.     right = b->Left + b->Width - 1;
  175.  
  176.     /* upper right edges    */
  177.     SetAPen( rp, ulpen );
  178.  
  179.     Move( rp, b->Left, bottom - 1 );
  180.     Draw( rp, b->Left, b->Top );
  181.     Draw( rp, right - 1, b->Top );
  182.  
  183.     /* lower right edges    */
  184.     SetAPen( rp, lrpen );
  185.  
  186.     Move( rp, right, b->Top + 1 );
  187.     Draw( rp, right, bottom );
  188.     Draw( rp, b->Left + 1, bottom );
  189. }
  190.  
  191.